package com.lc.hongtai.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.lc.hongtai.R;
import com.lc.hongtai.adapter.MyGridAdapter;
import com.lc.hongtai.conn.JsonAccessToken;
import com.lc.hongtai.conn.JsonTeamWork;
import com.lc.hongtai.toast.LovelyToast;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;

/**
 * Created by Administrator on 2017/4/20.
 */

public class HezuoActivity extends BaseActivity implements View.OnClickListener {
    @BoundView(R.id.gridview)
    private GridView gridview;

    @BoundView(R.id.iv_back)
    private ImageView iv_back;

    @BoundView(R.id.img_hezuo)
    private ImageView img_hezuo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hezuo);
        gridview.setAdapter(new MyGridAdapter(this));
        iv_back.setOnClickListener(this);
        getAccessToken();
    }


    private void getAccessToken() {
        new JsonAccessToken("index/hzdw", new AsyCallBack<JsonAccessToken.Info>() {
            @Override
            public void onSuccess(String toast, int type, JsonAccessToken.Info info) throws Exception {
                if (info != null) {
                    if (!TextUtils.isEmpty(info.access_token)) {
                        //   wv01.loadUrl(getIntent().getStringExtra("url") + "&access_token=" + info.access_token);
                        initData(info.access_token);

                    } else {
                        //UtilToast.show(AdvertisingActivity.this, "安全验证失败！");
                        LovelyToast.makeText(HezuoActivity.this, "安全验证失败!", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    }
                }
            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
                //  UtilToast.show(AdvertisingActivity.this, "安全验证失败！");
                LovelyToast.makeText(HezuoActivity.this, "安全验证失败!", 0, LovelyToast
                        .SUCCESS, LovelyToast.SCALE);

            }
        }).execute(this, true);

    }

    private void initData(String access_token) {
        new JsonTeamWork(access_token, new AsyCallBack<JsonTeamWork.Info>() {

            @Override
            public void onStart(int type) throws Exception {
                super.onStart(type);

            }

            @Override
            public void onSuccess(String toast, int type, JsonTeamWork.Info info) throws Exception {
                super.onSuccess(toast, type, info);
                Glide.with(context)
                        .load(info.friend.get(0).img)
                        .into(img_hezuo);
            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
            }

            @Override
            public void onEnd(String toast, int type) throws Exception {
                super.onEnd(toast, type);
            }
        }).execute(HezuoActivity.this, false);
    }


    @Override
    public void onClick(View view) {
        super.onClick(view);

        switch (view.getId()) {
            case R.id.iv_back:
                finish();

                break;
        }

    }
}
